<template>
  <div class="container">
    <!-- 搜索区域 -->
    <div class="search-section card">
      <div class="search-container">
        <input type="text" placeholder="搜索项目、示例或技术文章..." class="search-input">
        <button class="search-btn">搜索</button>
      </div>
    </div>

    <!-- 快速筛选导航区 -->
    <div class="filter-section card">
      <div class="filter-group">
        <h3 class="filter-title">语言</h3>
        <div class="filter-tags">
          <span v-for="lang in languages" :key="lang" class="tag" :class="{ active: selectedLang === lang }" @click="selectedLang = lang">
            {{ lang }}
          </span>
        </div>
      </div>
      <div class="filter-group">
        <h3 class="filter-title">框架</h3>
        <div class="filter-tags">
          <span v-for="framework in frameworks" :key="framework" class="tag" :class="{ active: selectedFramework === framework }" @click="selectedFramework = framework">
            {{ framework }}
          </span>
        </div>
      </div>
      <div class="filter-group">
        <h3 class="filter-title">类型</h3>
        <div class="filter-tags">
          <span v-for="type in types" :key="type" class="tag" :class="{ active: selectedType === type }" @click="selectedType = type">
            {{ type }}
          </span>
        </div>
      </div>
      <div class="filter-group">
        <h3 class="filter-title">难度</h3>
        <div class="filter-tags">
          <span v-for="level in levels" :key="level" class="tag" :class="{ active: selectedLevel === level }" @click="selectedLevel = level">
            {{ level }}
          </span>
        </div>
      </div>
    </div>

    <!-- 精选项目区域 -->
    <div class="section">
      <div class="section-header">
        <h2 class="section-title">🔥 热门开源项目</h2>
        <a href="#" class="view-more">查看更多</a>
      </div>
      <div class="project-grid">
        <div v-for="project in featuredProjects" :key="project.id" class="project-card card">
          <div class="project-badge" :class="project.badgeClass">{{ project.badgeText }}</div>
          <h3 class="project-title">{{ project.title }}</h3>
          <p class="project-desc">{{ project.description }}</p>
          <div class="project-tech">
            <span v-for="tech in project.tech.split('+')" :key="tech" class="tech-tag">{{ tech }}</span>
          </div>
          <div class="project-footer">
            <div class="project-meta">
              <span class="rating">⭐️ {{ project.rating }}</span>
              <span class="author">by @{{ project.author }}</span>
            </div>
            <div class="project-actions">
              <button class="btn btn-primary">演示</button>
              <button class="btn btn-secondary">详情</button>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 最新示例区 -->
    <div class="section">
      <div class="section-header">
        <h2 class="section-title">🧪 技术点演示</h2>
        <a href="#" class="view-more">查看更多</a>
      </div>
      <div class="example-list card">
        <div v-for="example in latestExamples" :key="example.id" class="example-item">
          <div class="example-info">
            <h3 class="example-title">{{ example.title }}</h3>
            <p class="example-desc">{{ example.description }}</p>
            <div class="example-tags">
              <span v-for="tag in example.tags" :key="tag" class="tag">{{ tag }}</span>
            </div>
          </div>
          <div class="example-actions">
            <button class="btn btn-primary">演示</button>
            <button class="btn btn-secondary">查看源码</button>
          </div>
        </div>
      </div>
    </div>

    <!-- 技术地图入口 -->
    <div class="section">
      <div class="section-header">
        <h2 class="section-title">技术栈地图</h2>
        <a href="#" class="view-more">完整地图</a>
      </div>
      <div class="tech-map card">
        <div v-for="stack in techStacks" :key="stack.id" class="tech-stack">
          <div class="stack-header">
            <span class="stack-name">{{ stack.name }}</span>
            <span class="stack-count">{{ stack.count }}个项目</span>
          </div>
          <div class="stack-progress">
            <div class="progress-bar" :style="{ width: stack.progress + '%' }"></div>
          </div>
          <div class="stack-techs">
            <span v-for="(tech, index) in stack.techs" :key="tech" class="tech-tag">
              {{ tech }}
            </span>
          </div>
        </div>
      </div>
    </div>

    <!-- 开发者生态入口 -->
    <div class="section">
      <div class="section-header">
        <h2 class="section-title">👑 本月贡献榜</h2>
        <a href="#" class="view-more">完整榜单</a>
      </div>
      <div class="contributors card">
        <div v-for="contributor in topContributors" :key="contributor.id" class="contributor-item">
          <img :src="contributor.avatar" :alt="contributor.name" class="contributor-avatar">
          <div class="contributor-info">
            <span class="contributor-name">@{{ contributor.name }}</span>
            <span class="contributor-stats">{{ contributor.contribution }}</span>
          </div>
          <div class="contributor-badge" :class="contributor.badgeClass">{{ contributor.badge }}</div>
        </div>
        <div class="contributor-actions">
          <button class="btn btn-primary">加入交流群</button>
          <button class="btn btn-secondary">投稿指南</button>
          <button class="btn btn-secondary">文档贡献入口</button>
        </div>
      </div>
    </div>

    <!-- 平台动态 -->
    <div class="section">
      <div class="section-header">
        <h2 class="section-title">📰 平台动态</h2>
        <a href="#" class="view-more">历史动态</a>
      </div>
      <div class="news-list card">
        <div v-for="news in platformNews" :key="news.id" class="news-item">
          <div class="news-date">[{{ news.date }}]</div>
          <div class="news-content">{{ news.content }}</div>
          <div class="news-tags">
            <span v-for="tag in news.tags" :key="tag" class="tag">{{ tag }}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
const selectedLang = ref('')
const selectedFramework = ref('')
const selectedType = ref('')
const selectedLevel = ref('')

const languages = ['Go', 'Java', 'Rust', 'Python', 'Node.js', 'TypeScript', 'C++', 'PHP']
const frameworks = ['Spring Boot', 'Gin', 'Actix', 'Vue 3', 'React', 'Next.js', 'NestJS']
const types = ['项目', '示例', '工具库', '组件', 'UI Kit', '插件', '模板']
const levels = ['初学者', '中级开发者', '架构实践', '专家级']

const featuredProjects = [
  {
    id: 1,
    title: '电商后台系统',
    description: '基于微服务架构的完整电商解决方案',
    tech: 'Go+Vue3+MySQL+Redis',
    rating: '4.8',
    author: 'jakechen',
    badgeClass: 'badge-new',
    badgeText: '新上线'
  },
  {
    id: 2,
    title: 'DevOps 管理平台',
    description: '一站式DevOps工具链集成平台',
    tech: 'Java+React+MongoDB',
    rating: '4.5',
    author: 'denglee',
    badgeClass: 'badge-popular',
    badgeText: '热门'
  },
  {
    id: 3,
    title: 'AI 模型训练平台',
    description: '支持多种深度学习框架的模型训练平台',
    tech: 'Python+PyTorch+FastAPI',
    rating: '4.7',
    author: 'alex',
    badgeClass: 'badge-ai',
    badgeText: 'AI'
  }
]

const latestExamples = [
  {
    id: 1,
    title: 'JWT 登录流程',
    description: '完整的JWT认证实现示例，包含token刷新机制',
    tags: ['认证', '安全', 'JWT']
  },
  {
    id: 2,
    title: 'SQL CTE分页',
    description: 'PostgreSQL CTE实现高效分页查询',
    tags: ['数据库', 'PostgreSQL', '性能优化']
  },
  {
    id: 3,
    title: 'Rust 并发 actor 模型',
    description: '基于actor模型的并发编程示例',
    tags: ['并发', 'Rust', 'Actor']
  }
]

const techStacks = [
  {
    id: 1,
    name: 'Go',
    count: 128,
    progress: 85,
    techs: ['Gin', 'Gorm', 'Redis', 'Kafka', 'Docker']
  },
  {
    id: 2,
    name: 'Java',
    count: 156,
    progress: 90,
    techs: ['Spring Boot', 'JPA', 'Kafka', 'MyBatis']
  },
  {
    id: 3,
    name: 'Node.js',
    count: 98,
    progress: 75,
    techs: ['Express', 'MongoDB', 'TypeScript']
  }
]

const topContributors = [
  {
    id: 1,
    name: 'jakechen',
    avatar: '/avatars/jakechen.jpg',
    contribution: '发布项目 3 个，贡献示例 8 个',
    badge: '金牌贡献者',
    badgeClass: 'badge-gold'
  },
  {
    id: 2,
    name: 'linzh',
    avatar: '/avatars/linzh.jpg',
    contribution: '示例提交 5 个，文档更新 12 篇',
    badge: '银牌贡献者',
    badgeClass: 'badge-silver'
  }
]

const platformNews = [
  {
    id: 1,
    date: '2025-04-20',
    content: '发布支持「在线运行环境」的新功能，支持主流编程语言在线调试',
    tags: ['新功能', '在线环境']
  },
  {
    id: 2,
    date: '2025-04-10',
    content: '示例数量突破 1000 个，感谢所有贡献者的支持 🎉',
    tags: ['里程碑', '社区']
  }
]
</script>

<style scoped>
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.section {
  margin-bottom: 48px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.section-title {
  font-size: 28px;
  font-weight: bold;
  color: var(--text-color);
  margin: 0;
}

.view-more {
  color: var(--primary-color);
  text-decoration: none;
  font-size: 14px;
}

.view-more:hover {
  text-decoration: underline;
}

.search-section {
  margin-bottom: 32px;
  padding: 24px;
}

.search-container {
  display: flex;
  gap: 16px;
  max-width: 600px;
  margin: 0 auto;
}

.search-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px;
}

.search-btn {
  padding: 12px 24px;
  background: var(--primary-color);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.filter-section {
  padding: 24px;
  margin-bottom: 32px;
}

.filter-group {
  margin-bottom: 24px;
}

.filter-title {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.filter-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.tag {
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.tag:hover {
  background: var(--primary-color-light);
}

.tag.active {
  background: var(--primary-color);
  color: white;
}

.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 24px;
}

.project-card {
  position: relative;
  padding: 24px;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.project-card:hover {
  transform: translateY(-4px);
}

.project-badge {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
}

.badge-new {
  background: #10b981;
  color: white;
}

.badge-popular {
  background: #f59e0b;
  color: white;
}

.badge-ai {
  background: #6366f1;
  color: white;
}

.project-title {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 8px;
}

.project-desc {
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.project-tech {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.tech-tag {
  padding: 4px 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  font-size: 12px;
}

.project-footer {
  margin-top: auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.rating {
  color: #f59e0b;
  font-weight: bold;
}

.author {
  color: var(--text-secondary);
}

.project-actions {
  display: flex;
  gap: 8px;
}

.example-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.example-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.3s ease;
}

.example-item:hover {
  background-color: var(--bg-secondary);
}

.example-item:last-child {
  border-bottom: none;
}

.example-info {
  flex: 1;
}

.example-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 8px;
}

.example-desc {
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.example-tags {
  display: flex;
  gap: 8px;
}

.tech-map {
  padding: 24px;
}

.tech-stack {
  margin-bottom: 24px;
}

.stack-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.stack-name {
  font-weight: bold;
  font-size: 18px;
}

.stack-count {
  color: var(--text-secondary);
  font-size: 14px;
}

.stack-progress {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 4px;
  margin-bottom: 12px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary-color);
  border-radius: 4px;
}

.contributors {
  padding: 24px;
}

.contributor-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.contributor-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.contributor-info {
  flex: 1;
}

.contributor-name {
  font-weight: bold;
  display: block;
  margin-bottom: 4px;
}

.contributor-stats {
  color: var(--text-secondary);
  font-size: 14px;
}

.contributor-badge {
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: bold;
}

.badge-gold {
  background: #f59e0b;
  color: white;
}

.badge-silver {
  background: #9ca3af;
  color: white;
}

.contributor-actions {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 24px;
}

.news-list {
  padding: 24px;
}

.news-item {
  padding: 16px;
  border-bottom: 1px solid var(--border-color);
}

.news-date {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 8px;
}

.news-content {
  margin-bottom: 12px;
  line-height: 1.5;
}

.news-tags {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary {
  background: var(--primary-color);
  color: white;
  border: none;
}

.btn-primary:hover {
  background: var(--primary-color-dark);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-color);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
}

@media (max-width: 768px) {
  .container {
    padding: 16px;
  }

  .section {
    margin-bottom: 32px;
  }

  .section-title {
    font-size: 24px;
  }

  .project-grid {
    grid-template-columns: 1fr;
  }

  .example-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
  }

  .example-actions {
    width: 100%;
    justify-content: flex-end;
  }

  .contributor-actions {
    flex-direction: column;
  }

  .search-container {
    flex-direction: column;
  }

  .search-btn {
    width: 100%;
  }
}
</style> 